package com.headwind.logistics.log.controller;

import com.headwind.logistics.common.util.LayuiUtil;
import com.headwind.logistics.common.util.RestResult;
import com.headwind.logistics.common.util.ResultGenerator;
import com.headwind.logistics.log.Service.intl.LogServiceIntl;
import com.headwind.logistics.log.annotate.Log;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @Author 小恶魔
 * @Date 2020-07-21 14:57
 * @Version 1.0
 * @DESCRIPTION 功能操作日志控制器
 */
@Controller
@RequestMapping("/admin/log")
public class FunctionLogController {

    //日志业务逻辑层
    @Resource
    private LogServiceIntl logServiceIntl;

    //api统一响应数据格式
    @Resource
    private ResultGenerator resultGenerator;

    /**
     * 获取全部功能操作日志信息
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/queryAllFuncLog")
    @ResponseBody
    public LayuiUtil queryAllFuncLog(Integer page,Integer limit){
        //返回layui格式的数据
        return LayuiUtil.data(logServiceIntl.queryAllFunctionLog(null,null).size()
                ,logServiceIntl.queryAllFunctionLog(page, limit));
    }

    /**
     * 批量删除功能操作日志信息
     * @param funcIds
     * @return
     */
    @PostMapping("/batchDeleteFuncLog")
    @ResponseBody
    public RestResult batchDeleteFuncLogById(String funcIds){

        Integer count = logServiceIntl.batchDeleteFunctionLogById(funcIds);

        if (count > 0){
            return resultGenerator.getSuccessResult("删除"+count+"条数据",null);
        }

        return resultGenerator.getFailResult("删除失败，重新试试");
    }

}
